package com.zmn.mcc.business.impl.sys;

import com.alibaba.fastjson.JSONObject;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.mcc.business.interfaces.sys.SysBService;
import com.zmn.mcc.model.entity.sys.McSys;
import com.zmn.mcc.services.interfaces.sys.SysService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author heguanghua
 * @since 2020/04/14 22:18
 */
@Service
public class SysBServiceImpl implements SysBService {
    protected Logger logger = LoggerFactory.getLogger(SysBServiceImpl.class);

    @Resource
    private SysService sysService;


    // region 新增/修改系统

    @Override
    public ResponseDTO addSys(McSys sys) {
        
        try {

            if(StringUtil.isBlank(sys.getSysName())) {
                return ResponseDTO.fail("请填写系统名称");
            }

            // 系统信息
            sysService.insert(sys);

            return ResponseDTO.success(sys.getSysId(), "新增系统成功");

        } catch (Exception ex) {
            logger.error(String.format("[ZMN]新增系统失败,sys:[%s],ex:[%s]", JSONObject.toJSONString(sys), ex.getMessage()));
            return ResponseDTO.fail("新增系统失败");
        }
    }

    @Override
    public ResponseDTO modifySys(McSys sys) {
        
        try {

            if(StringUtil.isBlank(sys.getSysName())) {
                return ResponseDTO.fail("请填写系统名称");
            }

            // 系统信息
            sysService.updateByKey(sys);

            return ResponseDTO.success(sys.getSysId(), "修改系统成功");

        } catch (Exception ex) {
            logger.error(String.format("[ZMN]修改系统失败,sys:[%s],ex:[%s]", JSONObject.toJSONString(sys), ex.getMessage()));
            return ResponseDTO.fail("修改系统失败");
        }
    }
    // endregion
}
